<template xmlns:v-action="http://www.w3.org/1999/xhtml">
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="48">
          <a-col :md="8" :sm="24">
            <a-form-item label="手机号码">
              <a-input v-model="queryParam.mobile" type="number" onKeypress="return (/[\d]/.test(String.fromCharCode(event.keyCode)))" placeholder="请输入"/>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <a-form-item label="商圈">
              <a-select allowClear v-model="queryParam.companyId">
                <a-select-option v-for="item in companys" :key="item.id">{{item.name}}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>

          <a-col :md="8" :sm="24">
            <span class="table-page-search-submitButtons">
              <a-button v-action:query type="primary" @click="$refs.table.refresh(true)">查询</a-button>
              <a-button v-action:query style="margin-left: 8px" @click="() => queryParam = {}">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <div class="table-operator">
      <!--<a-button type="primary" icon="plus" @click="handleAdd()">新建</a-button>-->
      <a-button type="danger" icon="delete" @click="handleZero">积分清零</a-button>
    </div>

    <s-table
      ref="table"
      size="default"
      :columns="columns"
      :data="loadData"
      :indentSize="40"
      :scroll="{ x: 1200 }"
    >
       <span slot="avatarUrl" slot-scope="text,record">
          <template>
            <div class="dfhead">
              <img :src="record.avatarUrl" alt="" style="width: 50px;height: auto;">
            </div>
        </template>
      </span>
      <span slot="gender" slot-scope="text,record">
          <template>
              {{record.gender==2?'女':'男'}}
        </template>
      </span>
      <span slot="status" slot-scope="text,record">
          <template>
              {{record.status==0?'老会员':'新会员'}}
        </template>
      </span>

      <span slot="integral" slot-scope="text,record">
          <template>
<!--              <a  @click="$refs.modal.detail(record)">{{record.integral}}</a>-->
              <a  @click="handleDetail(record)">{{record.integral}}</a>
        </template>
      </span>

      <span slot="action" slot-scope="text, record">
        <template>
          <a  @click="$refs.modal.edit(record,0)">积分兑换</a>
          <a-divider type="vertical"/>
          <a @click="$refs.modal.edit(record,1)">积分补录</a>
        </template>
        <!--<a-dropdown>
          <a class="ant-dropdown-link">
            更多 <a-icon type="down"/>
          </a>
          <a-menu slot="overlay">
            &lt;!&ndash;<a-menu-item>
              <a @click="">积分清零</a>
            </a-menu-item>&ndash;&gt;
            <a-menu-item>
              <a @click="$refs.modal.edit(record,1)">积分补录</a>
            </a-menu-item>
          </a-menu>
        </a-dropdown>-->
      </span>
    </s-table>

    <Edit ref="modal" @ok="handleOk"></Edit>
  </a-card>
</template>

<script>
  import STable from '@/components/table/'
  import { selectPage } from '../../../api/memberService/member'
  import Edit from './Edit'
  import Info from '../../businessService/editor/info'
  import { selectAll } from '../../../api/companyService/company'

  export default {
    components: {
      Info,
      STable,
      Edit
    },
    //--############  data() ###############-->
    data() {
      return {
        description: '',
        // 高级搜索 展开/关闭
        advanced: false,
        // 查询参数
        queryParam: {},

        companys:[],
        // 表头
        columns: [
          {
            title: '商圈名称',
            dataIndex: 'companyName'
          },
          {
            title: '微信头像',
            dataIndex: 'avatarUrl',
            scopedSlots: { customRender: 'avatarUrl' }
          },
          {
            title: '昵称',
            dataIndex: 'nickName'
          },
          {
            title: '性别',
            dataIndex: 'gender',
            scopedSlots: { customRender: 'gender' }
          },
          {
            title: '积分',
            dataIndex: 'integral',
            sorter: true,
            scopedSlots: { customRender: 'integral' }
          },
          {
            title: '手机号码',
            dataIndex: 'mobile'
          },
          {
            title: '会员状态',
            dataIndex: 'status',
            scopedSlots: { customRender: 'status' }
          },
          /*{
            title: '操作',
            dataIndex: 'action',
            width: '200px',
            scopedSlots: { customRender: 'action' }
          }
*/
        ],
        // 加载数据方法 必须为 Promise 对象
        loadData: parameter => {
          if(parameter.sortOrder==undefined){
          }else if(parameter.sortOrder=="ascend"){
            this.queryParam.sort=0
          }else if(parameter.sortOrder=="descend"){
            this.queryParam.sort=1
          }
          return selectPage(Object.assign(parameter, this.queryParam))
            .then(res => {
              return res.result
            })
        },

        selectedRowKeys: [],
        selectedRows: []
      }
    },
    created(){
      selectAll().then(res => {
        this.companys = res.result
      })
    },
    //--############  data() ###############-->
    //--############  methods() ###############-->
    methods: {
      onSelectChange(selectedRowKeys, selectedRows) {
        this.selectedRowKeys = selectedRowKeys
        this.selectedRows = selectedRows
      },
      toggleAdvanced() {
        this.advanced = !this.advanced
      },
      handleOk() {
        // 新增/修改 成功时，重载列表
        this.$refs.table.refresh(true)
      },
      handleDetail(record){
        this.$emit('onEdit', record)
      },
      handleZero(){
        // if(this.queryParam.companyId==null){
        //   this.$message.warn('请先选择商圈！')
        //   return
        // }
        this.$refs.modal.edit(undefined,2,this.queryParam.companyId);
      }
    }
    //--############  methods() ###############-->
  }
</script>
<style scoped>
  .dfhead{
    width: 50px;
    height: 50px;
    background: url("../../../assets/icons/dfhead.png") no-repeat center;
    background-size: 50px;
    border-radius: 25px;
    overflow: hidden;
  }
</style>